<!--
 * @Author: wangming
 * @Date: 2021-06-09 15:18:59
 * @LastEditors: wangming
 * @LastEditTime: 2021-10-18 18:31:24
 * @Description: file content
-->
<template>
  <div class="ks-col">
    <el-input
      prefix-icon="el-icon-search"
      placeholder="输入关键字进行过滤"
      v-model="filterText"
      v-if="config.__config.showSearch"
    >
    </el-input>
    <el-tree
      :data="data"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree"
    />
  </div>
</template>

<script>
import mixins from "../mixins.js";
export default {
  mixins: [mixins],
  data() {
    return {
      filterText: "",
      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "二级 1-1",
              children: [
                {
                  id: 9,
                  label: "三级 1-1-1",
                },
                {
                  id: 10,
                  label: "三级 1-1-2",
                },
              ],
            },
          ],
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 5,
              label: "二级 2-1",
            },
            {
              id: 6,
              label: "二级 2-2",
            },
          ],
        },
        {
          id: 3,
          label: "一级 3",
          children: [
            {
              id: 7,
              label: "二级 3-1",
            },
            {
              id: 8,
              label: "二级 3-2",
            },
          ],
        },
      ],
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-tree {
  background-color: transparent;
}
</style>
